Class Train

java.lang.Object
  extended by Train

public class Train
extends java.lang.Object


Constructor Summary
Train()
          Constructs an empty train; i.e., one that has no cars.
 
Method Summary
 void addCar(Car car)
          Adds the specified car to this train.
 boolean cancelTicket(int carId, int seatNo)
          Cancels the ticket for the specified seat in the specified car.
 java.util.ArrayList<Car> cars()
          Returns this trains's list of cars.
 boolean issueTicket(boolean businessClassSeat)
          Attempts to issue a ticket for a business class seat or an economy class seat, as specified by the method's argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Train

public Train()
Constructs an empty train; i.e., one that has no cars.

Method Detail

addCar

public void addCar(Car car)
Adds the specified car to this train.


cancelTicket

public boolean cancelTicket(int carId,
                            int seatNo)
Cancels the ticket for the specified seat in the specified car. Returns true if successful, false otherwise.


cars

public java.util.ArrayList<Car> cars()
Returns this trains's list of cars. This method is intended for testing purposes only, and should not be called by other objects, as it may be removed from the final version of this class.

Returns:
A list of the cars in the train

issueTicket

public boolean issueTicket(boolean businessClassSeat)
Attempts to issue a ticket for a business class seat or an economy class seat, as specified by the method's argument. It will attempt to book a seat in the first car of the appropriate type, but if a seat is not available it will attempt to book a seat in the second car of the appropriate type, and so on. A request to issue a ticket in a business-class car will never result in a seat being reserved in an economy-class car, and vice-versa. Returns true if successful, false otherwise.